var json_resp;

function mycarousel_itemLoadCallback(carousel, state)
{
    for (var i = carousel.first; i <= carousel.last; i++) {
        if (carousel.has(i)) {
            continue;
        }

        if (i > json_resp.response.docs.length) {
            break;
        }

	//var j = i-1;

        carousel.add(i, mycarousel_getItemHTML(json_resp.response.docs[i-1]));
    }
};


/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
    return '<div class="bestSellerItemContainer"><div class="itemBox" style="border: 1px solid #808080; width: 150px; height: 150px; background-image: none; background-position: center center; background-repeat: no-repeat;"><img src="' + item.turl + '" width="150" height="150" alt="' + item.turl + '" /></div><div class="bestSellerCarouselTxt" title="' + item.title + '">'+ item.title +'</div><div class="bestSellerCarouselPrice">'+ item.sprice + '</div>';    
};


(function ($) {


AjaxSolr.ResultWidget = AjaxSolr.AbstractWidget.extend({  
	afterRequest: function () {    			
			
			json_resp = this.Manager.response;
			jQuery('#mycarousel').jcarousel({
        			size: json_resp.response.docs.length,
	        		itemLoadCallback: {onBeforeAnimation: mycarousel_itemLoadCallback}
    			});


		}
});

})(jQuery);
 

